home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2001 March
/
PCWorld_2001-03_cd.bin
/
Software
/
TemaCD
/
classbuild
/
ClassBuilder 2.2 PR405 Setup.exe
/
{app}
/
Include
/
CB_CriticalSection.h
< prev
next >
Wrap
C/C++ Source or Header
|
2000-10-17
|
1KB
|
77 lines
#ifndef CB_CRITICAL_SECTION
#define CB_CRITICAL_SECTION
#ifdef _WIN32
// This is Windows specific, need to change this for other platforms.
#include <windows.h>
#include <process.h>
class CriticalSection
{
private:
CRITICAL_SECTION _criticalSection;
public:
CriticalSection()
{
InitializeCriticalSection(&_criticalSection);
}
~CriticalSection()
{
DeleteCriticalSection(&_criticalSection);
}
void Enter()
{
EnterCriticalSection(&_criticalSection);
}
void Leave()
{
LeaveCriticalSection(&_criticalSection);
}
};
#else
// Bogus implementation of this class. We won't use multithreading so critical sections are useless.
class CriticalSection
{
private:
// no members
public:
CriticalSection()
{
}
~CriticalSection()
{
}
void Enter()
{
}
void Leave()
{
}
};
#endif
class CriticalSectionLock
{
private:
CriticalSection* _criticalSection;
public:
CriticalSectionLock(CriticalSection& criticalSection)
: _criticalSection(&criticalSection)
{
_criticalSection->Enter();
}
~CriticalSectionLock()
{
_criticalSection->Leave();
}
};
#endif